load("@build_bazel_rules_android//android:rules.bzl", "android_library")
load("@tink_base//:tink_version.bzl", "TINK_VERSION_LABEL")
load("@tink_base//tools:common.bzl", "template_rule")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])

# Primitives

java_library(
    name = "aead",
    srcs = ["Aead.java"],
)

java_library(
    name = "streaming_aead",
    srcs = ["StreamingAead.java"],
)

java_library(
    name = "deterministic_aead",
    srcs = ["DeterministicAead.java"],
)

java_library(
    name = "hybrid_decrypt",
    srcs = ["HybridDecrypt.java"],
)

java_library(
    name = "hybrid_encrypt",
    srcs = ["HybridEncrypt.java"],
)

java_library(
    name = "mac",
    srcs = ["Mac.java"],
)

java_library(
    name = "key_wrap",
    srcs = ["KeyWrap.java"],
)

java_library(
    name = "public_key_sign",
    srcs = ["PublicKeySign.java"],
)

java_library(
    name = "public_key_verify",
    srcs = ["PublicKeyVerify.java"],
)

# Other public interfaces

java_library(
    name = "crypto_format",
    srcs = ["CryptoFormat.java"],
    deps = ["//proto:tink_java_proto"],
)

android_library(
    name = "crypto_format-android",
    srcs = ["CryptoFormat.java"],
    deps = ["//proto:tink_java_proto_lite"],
)

java_library(
    name = "primitive_wrapper",
    srcs = ["PrimitiveWrapper.java"],
    deps = [":primitive_set"],
)

android_library(
    name = "primitive_wrapper-android",
    srcs = ["PrimitiveWrapper.java"],
    deps = [":primitive_set-android"],
)

java_library(
    name = "kms_client",
    srcs = ["KmsClient.java"],
    deps = [":aead"],
)

java_library(
    name = "kms_clients",
    srcs = ["KmsClients.java"],
    deps = [":kms_client"],
)

java_library(
    name = "kms_clients_test_util",
    testonly = 1,
    srcs = ["KmsClientsTestUtil.java"],
    deps = [":kms_clients"],
)

java_library(
    name = "keyset_writer",
    srcs = ["KeysetWriter.java"],
    deps = ["//proto:tink_java_proto"],
)

android_library(
    name = "keyset_writer-android",
    srcs = ["KeysetWriter.java"],
    deps = ["//proto:tink_java_proto_lite"],
)

java_library(
    name = "binary_keyset_writer",
    srcs = ["BinaryKeysetWriter.java"],
    deps = [
        ":keyset_writer",
        "//proto:tink_java_proto",
    ],
)

android_library(
    name = "binary_keyset_writer-android",
    srcs = ["BinaryKeysetWriter.java"],
    deps = [
        ":keyset_writer-android",
        "//proto:tink_java_proto_lite",
    ],
)

java_library(
    name = "json_keyset_writer",
    srcs = ["JsonKeysetWriter.java"],
    deps = [
        ":keyset_writer",
        "//proto:tink_java_proto",
        "//src/main/java/com/google/crypto/tink/subtle:base64",
        "@maven//:com_google_code_gson_gson",
    ],
)

android_library(
    name = "json_keyset_writer-android",
    srcs = ["JsonKeysetWriter.java"],
    deps = [
        ":keyset_writer-android",
        "//proto:tink_java_proto_lite",
        "//src/main/java/com/google/crypto/tink/subtle:base64",
        "@maven//:com_google_code_gson_gson",
    ],
)

java_library(
    name = "keyset_reader",
    srcs = ["KeysetReader.java"],
    deps = ["//proto:tink_java_proto"],
)

android_library(
    name = "keyset_reader-android",
    srcs = ["KeysetReader.java"],
    deps = ["//proto:tink_java_proto_lite"],
)

java_library(
    name = "binary_keyset_reader",
    srcs = ["BinaryKeysetReader.java"],
    deps = [
        ":keyset_reader",
        "//proto:tink_java_proto",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "binary_keyset_reader-android",
    srcs = ["BinaryKeysetReader.java"],
    deps = [
        ":keyset_reader-android",
        "//proto:tink_java_proto_lite",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "json_keyset_reader",
    srcs = ["JsonKeysetReader.java"],
    deps = [
        ":keyset_reader",
        ":util",
        "//proto:tink_java_proto",
        "//src/main/java/com/google/crypto/tink/subtle:base64",
        "@com_google_protobuf//:protobuf_javalite",
        "@maven//:com_google_code_gson_gson",
    ],
)

android_library(
    name = "json_keyset_reader-android",
    srcs = ["JsonKeysetReader.java"],
    deps = [
        ":keyset_reader-android",
        ":util-android",
        "//proto:tink_java_proto_lite",
        "//src/main/java/com/google/crypto/tink/subtle:base64",
        "@com_google_protobuf//:protobuf_javalite",
        "@maven//:com_google_code_gson_gson",
    ],
)

java_library(
    name = "private_key_manager",
    srcs = ["PrivateKeyManager.java"],
    deps = [
        ":key_manager",
        "//proto:tink_java_proto",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "private_key_manager-android",
    srcs = ["PrivateKeyManager.java"],
    deps = [
        ":key_manager-android",
        "//proto:tink_java_proto_lite",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "privileged_registry",
    srcs = ["PrivilegedRegistry.java"],
    visibility = ["//visibility:public"],
    deps = [
        ":registry",
        "//proto:tink_java_proto",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "privileged_registry-android",
    srcs = ["PrivilegedRegistry.java"],
    visibility = ["//visibility:public"],
    deps = [
        ":registry-android",
        "//proto:tink_java_proto_lite",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "key_type_manager",
    srcs = ["KeyTypeManager.java"],
    deps = [
        ":key_template",
        "//proto:tink_java_proto",
        "//src/main/java/com/google/crypto/tink/annotations:alpha",
        "//src/main/java/com/google/crypto/tink/config/internal:tink_fips_util",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "key_type_manager-android",
    srcs = ["KeyTypeManager.java"],
    deps = [
        ":key_template-android",
        "//proto:tink_java_proto_lite",
        "//src/main/java/com/google/crypto/tink/annotations:alpha",
        "//src/main/java/com/google/crypto/tink/config/internal:tink_fips_util-android",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "key_template",
    srcs = ["KeyTemplate.java"],
    deps = [
        "//proto:tink_java_proto",
        "@com_google_protobuf//:protobuf_javalite",
        "@maven//:com_google_errorprone_error_prone_annotations",
    ],
)

android_library(
    name = "key_template-android",
    srcs = ["KeyTemplate.java"],
    deps = [
        "//proto:tink_java_proto_lite",
        "@com_google_protobuf//:protobuf_javalite",
        "@maven//:com_google_errorprone_error_prone_annotations",
    ],
)

java_library(
    name = "key_templates",
    srcs = ["KeyTemplates.java"],
    deps = [
        ":key_template",
        ":registry",
    ],
)

android_library(
    name = "key_templates-android",
    srcs = ["KeyTemplates.java"],
    deps = [
        ":key_template-android",
        ":registry-android",
    ],
)

java_library(
    name = "config",
    srcs = ["Config.java"],
    deps = [
        ":catalogue",
        ":key_manager",
        ":registry",
        "//proto:config_java_proto",
    ],
)

android_library(
    name = "config-android",
    srcs = ["Config.java"],
    deps = [
        ":catalogue-android",
        ":key_manager-android",
        ":registry-android",
        "//proto:config_java_proto_lite",
    ],
)

java_library(
    name = "private_key_manager_impl",
    srcs = ["PrivateKeyManagerImpl.java"],
    deps = [
        ":key_manager_impl",
        ":key_type_manager",
        ":private_key_manager",
        ":private_key_type_manager",
        "//proto:tink_java_proto",
        "//src/main/java/com/google/crypto/tink/annotations:alpha",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "private_key_manager_impl-android",
    srcs = ["PrivateKeyManagerImpl.java"],
    deps = [
        ":key_manager_impl-android",
        ":key_type_manager-android",
        ":private_key_manager-android",
        ":private_key_type_manager-android",
        "//proto:tink_java_proto_lite",
        "//src/main/java/com/google/crypto/tink/annotations:alpha",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "no_secret_keyset_handle",
    srcs = ["NoSecretKeysetHandle.java"],
    deps = [
        ":keyset_reader",
        ":registry_cluster",
        "//proto:tink_java_proto",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "no_secret_keyset_handle-android",
    srcs = ["NoSecretKeysetHandle.java"],
    deps = [
        ":keyset_reader-android",
        ":registry_cluster-android",
        "//proto:tink_java_proto_lite",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "cleartext_keyset_handle",
    srcs = ["CleartextKeysetHandle.java"],
    deps = [
        ":keyset_reader",
        ":keyset_writer",
        ":registry_cluster",
        "//proto:tink_java_proto",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "cleartext_keyset_handle-android",
    srcs = ["CleartextKeysetHandle.java"],
    deps = [
        ":keyset_reader-android",
        ":keyset_writer-android",
        ":registry_cluster-android",
        "//proto:tink_java_proto_lite",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "private_key_type_manager",
    srcs = ["PrivateKeyTypeManager.java"],
    deps = [
        ":key_type_manager",
        "//src/main/java/com/google/crypto/tink/annotations:alpha",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "private_key_type_manager-android",
    srcs = ["PrivateKeyTypeManager.java"],
    deps = [
        ":key_type_manager-android",
        "//src/main/java/com/google/crypto/tink/annotations:alpha",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "util",
    srcs = ["Util.java"],
    deps = ["//proto:tink_java_proto"],
)

android_library(
    name = "util-android",
    srcs = ["Util.java"],
    deps = ["//proto:tink_java_proto_lite"],
)

java_library(
    name = "catalogue",
    srcs = ["Catalogue.java"],
    deps = [
        ":key_manager",
        ":primitive_wrapper",
    ],
)

android_library(
    name = "catalogue-android",
    srcs = ["Catalogue.java"],
    deps = [
        ":key_manager-android",
        ":primitive_wrapper-android",
    ],
)

java_library(
    name = "key_manager",
    srcs = ["KeyManager.java"],
    deps = [
        "//proto:tink_java_proto",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "key_manager-android",
    srcs = ["KeyManager.java"],
    deps = [
        "//proto:tink_java_proto_lite",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "key_manager_impl",
    srcs = ["KeyManagerImpl.java"],
    deps = [
        ":key_manager",
        ":key_type_manager",
        "//proto:tink_java_proto",
        "//src/main/java/com/google/crypto/tink/annotations:alpha",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "key_manager_impl-android",
    srcs = ["KeyManagerImpl.java"],
    deps = [
        ":key_manager-android",
        ":key_type_manager-android",
        "//proto:tink_java_proto_lite",
        "//src/main/java/com/google/crypto/tink/annotations:alpha",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "primitive_set",
    srcs = ["PrimitiveSet.java"],
    deps = [
        ":crypto_format",
        "//proto:tink_java_proto",
        "//src/main/java/com/google/crypto/tink/subtle:hex",
    ],
)

android_library(
    name = "primitive_set-android",
    srcs = ["PrimitiveSet.java"],
    deps = [
        ":crypto_format-android",
        "//proto:tink_java_proto_lite",
        "//src/main/java/com/google/crypto/tink/subtle:hex",
    ],
)

java_library(
    name = "registry",
    srcs = [
        "Registry.java",
    ],
    deps = [
        ":catalogue",
        ":key_manager",
        ":key_manager_impl",
        ":key_template",
        ":key_type_manager",
        ":primitive_set",
        ":primitive_wrapper",
        ":private_key_manager",
        ":private_key_manager_impl",
        ":private_key_type_manager",
        "//proto:tink_java_proto",
        "//src/main/java/com/google/crypto/tink/config/internal:tink_fips_util",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

android_library(
    name = "registry-android",
    srcs = [
        "Registry.java",
    ],
    deps = [
        ":catalogue-android",
        ":key_manager-android",
        ":key_manager_impl-android",
        ":key_template-android",
        ":key_type_manager-android",
        ":primitive_set-android",
        ":primitive_wrapper-android",
        ":private_key_manager-android",
        ":private_key_manager_impl-android",
        ":private_key_type_manager-android",
        "//proto:tink_java_proto_lite",
        "//src/main/java/com/google/crypto/tink/config/internal:tink_fips_util-android",
        "@com_google_protobuf//:protobuf_javalite",
    ],
)

java_library(
    name = "registry_cluster",
    srcs = [
        "KeysetHandle.java",
        "KeysetManager.java",
    ],
    deps = [
        ":aead",
        ":key_template",
        ":keyset_reader",
        ":keyset_writer",
        ":primitive_set",
        ":registry",
        ":util",
        "//proto:tink_java_proto",
        "//src/main/java/com/google/crypto/tink/internal:key_status_type_proto_converter",
        "//src/main/java/com/google/crypto/tink/internal:util",
        "//src/main/java/com/google/crypto/tink/tinkkey:key_access",
        "//src/main/java/com/google/crypto/tink/tinkkey:key_handle",
        "//src/main/java/com/google/crypto/tink/tinkkey:secret_key_access",
        "//src/main/java/com/google/crypto/tink/tinkkey/internal:internal_key_handle",
        "//src/main/java/com/google/crypto/tink/tinkkey/internal:proto_key",
        "@com_google_protobuf//:protobuf_javalite",
        "@maven//:com_google_code_findbugs_jsr305",
    ],
)

android_library(
    name = "registry_cluster-android",
    srcs = [
        "KeysetHandle.java",
        "KeysetManager.java",
    ],
    deps = [
        ":aead",
        ":key_template-android",
        ":keyset_reader-android",
        ":keyset_writer-android",
        ":primitive_set-android",
        ":registry-android",
        ":util-android",
        "//proto:tink_java_proto_lite",
        "//src/main/java/com/google/crypto/tink/internal:key_status_type_proto_converter-android",

        "//src/main/java/com/google/crypto/tink/internal:util-android",
        "//src/main/java/com/google/crypto/tink/tinkkey:key_access-android",
        "//src/main/java/com/google/crypto/tink/tinkkey:key_handle-android",
        "//src/main/java/com/google/crypto/tink/tinkkey:secret_key_access-android",
        "//src/main/java/com/google/crypto/tink/tinkkey/internal:internal_key_handle-android",
        "//src/main/java/com/google/crypto/tink/tinkkey/internal:proto_key-android",
        "@com_google_protobuf//:protobuf_javalite",
        "@maven//:com_google_code_findbugs_jsr305",
    ],
)

android_library(
    name = "pem_key_type",
    srcs = ["PemKeyType.java"],
    deps = [
        "//src/main/java/com/google/crypto/tink/subtle:base64",
        "//src/main/java/com/google/crypto/tink/subtle:elliptic_curves",
        "//src/main/java/com/google/crypto/tink/subtle:enums",
        "//src/main/java/com/google/crypto/tink/subtle:subtle_util_cluster",
    ],
)

template_rule(
    name = "version_java",
    src = "Version.java.templ",
    out = "Version.java",
    substitutions = {
        "TINK_VERSION_LABEL": "%s" % TINK_VERSION_LABEL,
    },
)

java_library(
    name = "version",
    srcs = [":version_java"],
)
